package com.jsm.tf.net.handler;

import com.jsm.tf.director.Director;
import com.jsm.tf.net.invoke.CommandInvoker;
import com.jsm.tf.net.message.Message;
import com.jsm.tf.net.message.response.LoginResponseMessage;
import com.jsm.tf.view.RoomListView;
import com.jsm.tf.view.dialog.TFDialog;
import de.felixroske.jfxsupport.GUIState;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class ResponseMessageHandler extends ChannelInboundHandlerAdapter {
    @Resource
    private CommandInvoker invoker;
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        invoker.invoke((Message) msg, ctx.channel());
        super.channelRead(ctx,msg);
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        log.error("channelInactive");
        TFDialog.showConfirmDialog(GUIState.getStage(), "与服务器断开连接,请重启游戏", "与服务器断开连接,请重启游戏");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        log.error("exceptionCaught ",cause);
        TFDialog.showConfirmDialog(GUIState.getStage(),"与服务器断开连接,请重启游戏","与服务器断开连接,请重启游戏");
    }
}
